package com.taxi.service;

import com.taxi.remote.ServiceOrderClient;
import com.taxi.remote.ServicePassengerUserClient;
import com.taxi.constant.IdentityConstant;
import com.taxi.dto.OrderDetailInfo;
import com.taxi.dto.OrderInfo;
import com.taxi.dto.PassengerUser;
import com.taxi.request.OrderRequest;
import com.taxi.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

/**
 * @Author: aniu
 * @Date: 2023/10/3
 * @ClassName: OrderInfoService
 * @Description: Write class functionality and purpose here.
 * @Version: 1.0
 */
@Service
public class OrderInfoService {
    @Autowired
    private ServiceOrderClient serviceOrderClient;
    @Autowired
    private ServicePassengerUserClient servicePassengerUserClient;

    public Result add(OrderRequest orderRequest) {
        PassengerUser user = servicePassengerUserClient.getUserByPhone(orderRequest.getPassengerPhone()).getData();
        orderRequest.setPassengerId(user.getId());
        return serviceOrderClient.add(orderRequest);
    }

    public Result cancel(Long orderId) {
        return serviceOrderClient.cancel(orderId, IdentityConstant.PASSENGER_IDENTITY);
    }

    public Result<OrderInfo> currentOrder(String phone, String passengerIdentity) {
        return serviceOrderClient.current(phone,passengerIdentity);
    }

    public Result<OrderDetailInfo> currentOrderDetail(Long orderId){
        return serviceOrderClient.currentOrderDetail(orderId);
    }

    public Result<ArrayList<OrderInfo>> getAllOrders(String phone, String passengerIdentity) {
        return serviceOrderClient.getAllOrders(phone,passengerIdentity);
    }
}
